/*
 * h5设计页面的reducer
 */
import { combineReducers } from 'redux';
import Immutable from 'immutable';

import data from './data.js';

import {BLANK_H5_DATA} from '../../utils/H5constants';

const initialState={
	id:BLANK_H5_DATA.id,
	uniqueCode:BLANK_H5_DATA.uniqueCode,//08598360843361eb7bfbe262d96bfbc7
	title:BLANK_H5_DATA.title,
	activePageId:null,
	contentEdit:false
};

function id(state=initialState.id,action){
	switch (action.type) {
		case 'INIT_DATA':
			return action.id;
	   	default:
		   	return state;
  	}
}

//当前h5的唯一性编号
function uniqueCode(state=initialState.uniqueCode,action){
	switch (action.type) {
		case 'INIT_DATA':
			return action.uniqueCode;
	   	default:
		   	return state;
  	}
}

function title(state=initialState.title,action){
	switch (action.type) {
		case 'INIT_DATA':
			return action.title;
	   	default:
		   	return state;
  	}
}

function activePageId(state=initialState.activePageId,action){
	switch (action.type) {
		case 'INIT_DATA':
			return action.firstPageId;
		case 'H5_LEFT_PAGE_CLICK':
			return action.clickPageId;
	   	default:
		   	return state;
  	}
}

//用于自动保存，判断页面是否变化
function contentEdit(state=initialState.contentEdit,action){
	switch (action.type) {
		case 'SAVE_H5_DATA':
			return false;
	   	default:
		   	return state;
  	}
}


export default combineReducers({id,uniqueCode,title,activePageId,contentEdit,data});
